#pragma once

#include "keyboard.h"
#include <windows.h>
#include "dxManager.h"
#include <dinput.h>
#include "camera.h"
#include "Entity.h"
#include "Audio.h"

#define SCREEN_WIDTH	640
#define SCREEN_HEIGHT	640
#define NUM_ENTITIES	8
#define NUM_LIGHTS		8
#define SKY_R 107
#define SKY_G 184
#define SKY_B 255

enum ent_type
{
	ENT_PLAYER = 0,
	ENT_ENEMY  = 1,
	ENT_LIGHT  = 2,
};

// A structure for our custom vertex type
struct CUSTOMVERTEX
{
    FLOAT x, y, z;      // The untransformed, 3D position for the vertex
    DWORD color;        // The vertex color
};

// Our custom FVF, which describes our custom vertex structure
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE)

class Entity;
class Audio;

class Game
{
private:
	// DirectX stuff
	HRESULT hr;

	RECT rct;

	ID3DXMesh				*world;
	ID3DXMesh				*box;
	ID3DXFont *m_font;

	D3DMATERIAL9			mtrl, skyMtrl;
	D3DCOLOR				fontColor;
	LPDIRECTINPUT8			g_lpDI;		// the direct input object
	LPDIRECTINPUTDEVICE8	g_lpDIDevice; // the direct input device
	D3DXMATRIX* matView;
	void initDirectInput();
	Camera camera;

	///////////// Stuff we actually care about /////////////
	Entity* entList[NUM_ENTITIES];
	//Entity* lightList[NUM_LIGHTS];

	void gameInit();
	bool inBattle;					// bool to flag in and out of battle
	void initMeshes();
	
	LPDIRECT3DVERTEXBUFFER9 g_pVB; // Buffer to hold vertices
public:
	HWND wndHandle;						// global window handle
	LPDIRECT3D9             pD3D;                                              
	LPDIRECT3DDEVICE9       pd3dDevice;
	HINSTANCE* hInst;				// holds the instance for this app
	Keyboard* keyboard;
	Audio* audio;
	int numLights;
	float red, green, blue;
	bool rave;

	Game();
	void Update();
	void Draw();
	void DrawWorld();
	void shutDown();
	void Init(D3DXMATRIX* viewMat);
	D3DXMATRIX* getView() {return matView;}
	bool createEntity(ent_type type, ID3DXMesh *mesh, D3DMATERIAL9 material, float x, float y, float z);
	void drawVB(LPDIRECT3DVERTEXBUFFER9 buffer);
	LPDIRECT3DVERTEXBUFFER9 createVertexBuffer(int size, DWORD usage);
	HRESULT SetupVB();

//	void moveLight(int whichLight, D3DXMatrix whateverblah);

	// TODO: GET THIS STUFF DONE
	// Needs:
	// A menu system. Keep track of the cursor position in Game class
	// A couple functions to make it easy to play sounds and music
	// A list of entities, all of which handle their own drawing and updating routines.
	// Some sort of system for playing attacking/magic animations. How do we do this?
		// An "Animation" class?
	// Keep track of the game's state. Such as "In world" or "In battle".
};